package com.wms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wms.annotation.MyLog;
import com.wms.entity.*;
import com.wms.service.OutboundService;
import com.wms.service.impl.OutboundServiceImpl;
import com.wms.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Ayases
 * @Date 2025/4/29 20:37
 * @Desc
 */
@RestController
@RequestMapping("/manage/outbound/")
public class OutboundController {
    @Autowired
    private OutboundService outboundServiceImpl;

    /**
     * 分页查询全部信息
     */
    @GetMapping("/findAll")
    @MyLog(value = "分页查询出库订单", type = "查询")
    public R findAll(OutboundDTO outboundDTO) {
        PageHelper.startPage(outboundDTO.getPageNum(), outboundDTO.getPageSize());
        List<OutboundVO> list = outboundServiceImpl.findAll(outboundDTO);
        PageInfo<OutboundVO> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    /**
     * 根据id删除一条记录
     */
    @GetMapping("/deleteOne")
    @MyLog(value = "根据ID删除出库订单", type = "删除")
    public R deleteOne(OutboundDTO outboundDTO) {
        outboundServiceImpl.deleteOne(outboundDTO.getOutboundId());
        return R.ok();
    }

    /**
     * 批量删除记录
     */
    @GetMapping("/deleteBatch")
    @MyLog(value = "批量删除出库订单", type = "删除")
    public R deleteBatch(OutboundDTO outboundDTO) {
        outboundServiceImpl.deleteBatch(outboundDTO.getSelectedIds());
        return R.ok();
    }

    /**
     * 拣货记录
     */
    @GetMapping("/pick")
    @MyLog(value = "拣货单条记录", type = "操作")
    public R pick(OutboundDTO outboundDTO) {
        outboundServiceImpl.pick(outboundDTO.getOutboundId());
        return R.ok();
    }

    /**
     * 批量拣货记录
     */
    @GetMapping("/pickBatch")
    @MyLog(value = "拣货批量记录", type = "操作")
    public R pickBatch(OutboundDTO outboundDTO) {
        outboundServiceImpl.pickBatch(outboundDTO.getSelectedIds());
        return R.ok();
    }

    /**
     * 确认记录
     */
    @GetMapping("/confirm")
    @MyLog(value = "确认单条出库订单", type = "操作")
    public R confirm(OutboundDTO outboundDTO) {
        outboundServiceImpl.confirm(outboundDTO.getOutboundId());
        return R.ok();
    }

    /**
     * 批量确认记录
     */
    @GetMapping("/confirmBatch")
    @MyLog(value = "确认批量出库订单", type = "操作")
    public R confirmBatch(OutboundDTO outboundDTO) {
        outboundServiceImpl.confirmBatch(outboundDTO.getSelectedIds());
        return R.ok();
    }

    /**
     * 搜索关联订单信息
     */
    @GetMapping("/searchRelateData")
    @MyLog(value = "搜索关联出库订单", type = "查询")
    public R searchRelateData(OutboundDTO outboundDTO) {
        List<OutboundVO> list = outboundServiceImpl.searchRelateData(outboundDTO.getOutboundId());
        return R.ok(list);
    }

    /**
     * 新增记录
     */
    @PostMapping("/saveDialogForm")
    @MyLog(value = "新增出库订单", type = "新增")
    public R saveDialogForm(@RequestBody SaveDialogFormDTO dto) {
        System.out.println(dto);
        outboundServiceImpl.saveDialogForm(dto);
        return R.ok();
    }


    /**
     * 订单详情查询
     */
    @GetMapping("/detail")
    @MyLog(value = "查询出库订单详情", type = "查询")
    public R detail(@RequestParam String outboundId) {
        SaveDialogFormDTO dto = outboundServiceImpl.getDetailByOutboundId(outboundId);
        return R.ok(dto);

    }

}
